<template>
  <div class="aside-nav">
    <div class="aside-collapse" @click="onCollapse">|||</div>
    <el-menu
      unique-opened
      router
      :collapse="isCollapse"
      :collapse-transition="false"
      class="el-menu-vertical-demo "
      background-color="#333744"
      text-color="#fff"
      active-text-color="#409EFF"
      :default-active="isActiveIndex"
    >
      <!-- 一级菜单 -->
      <el-submenu
        :index="'/' + obj.path"
        v-for="obj in menuNavList"
        :key="obj.id"
      >
        <template slot="title">
          <i :class="iconsObj[obj.id]"></i>
          <span>{{ obj.authName }}</span>
        </template>
        <!-- 一级菜单内容选项 -->
        <el-menu-item
          :index="'/' + item.path"
          v-for="item in obj.children"
          :key="item.id"
          @click="onSavePath('/' + item.path)"
          ><i class="el-icon-menu"></i>
          <span slot="title">{{ item.authName }}</span></el-menu-item
        >
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
import { getItem, setItem } from '@/utils/storage'
export default {
  name: 'AsideNav',
  props: {
    menuNavList: {
      type: Array,
      required: true
    }
  },
  data() {
    return {
      iconsObj: {
        125: 'iconfont icon-users',
        103: 'iconfont icon-tijikongjian',
        101: 'iconfont icon-shangpin',
        102: 'iconfont icon-danju',
        145: 'iconfont icon-baobiao'
      },
      isCollapse: false,
      isActiveIndex: ''
    }
  },
  created() {
    this.isActiveIndex = getItem('localPath')
  },
  methods: {
    // 左侧边栏折叠功能处理
    onCollapse() {
      this.isCollapse = !this.isCollapse
      this.$emit('collapse', this.isCollapse)
    },
    // 点击侧边栏，记录侧边栏激活状态
    onSavePath(path) {
      setItem('localPath', path)
    }
  }
}
</script>

<style scoped lang="less">
.aside-nav {
  .aside-collapse {
    height: 28px;
    line-height: 24px;
    font-size: 16px;
    color: #fff;
    text-align: center;
    letter-spacing: 0.2em;
    background-color: #4a5064;
    cursor: pointer;
  }
  .iconfont {
    padding-right: 10px;
  }
  .el-menu {
    border-right: unset;
  }
}
</style>
